package com.ledim.ledimview;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.ledim.activity.EditPlayListsActivity;
import com.ledim.activity.SearchActivity;
import com.ledim.bean.ChatRoomBean;
import com.ledim.datastatistics.LeDimAnalysisUtils;
import com.letv.android.young.client.R;
import com.letv.tracker2.enums.EventType;
import java.util.HashMap;

public class RoomPlayListAddView extends LinearLayout implements View.OnClickListener {

    private Context mContext;
    private TextView mAdd;
    private TextView mEdit;
    private ChatRoomBean mRoom;
    private boolean mIsMe;

    public RoomPlayListAddView(Context context) {
        super(context);
        mContext = context;
    }

    public RoomPlayListAddView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public RoomPlayListAddView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext = context;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
    }

    //绑定数据
    public void bindData(ChatRoomBean mRoom, boolean isMe) {
        this.mRoom = mRoom;
        this.mIsMe = isMe;
        init();
    }

    /**
     * 初始化界面
     */
    private void init() {
        mEdit = (TextView) findViewById(R.id.room_edit_play_list);
        mAdd = (TextView) findViewById(R.id.room_add_play_list);

        mAdd.setOnClickListener(this);
        mEdit.setOnClickListener(this);

        if (mIsMe) {
            mAdd.setVisibility(View.VISIBLE);
            mEdit.setVisibility(View.VISIBLE);
        } else {
            mAdd.setVisibility(View.GONE);
            mEdit.setVisibility(View.GONE);
        }
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.room_add_play_list:
                //添加add按钮点击上报
                HashMap<String, String> params = new HashMap<String, String>();
                params.put("buttonName", "addTo");
                LeDimAnalysisUtils.reportEvent(LeDimAnalysisUtils.ROOM_ADD_CODE, EventType.Click, params);
                
                Intent intent1 = new Intent(mContext, SearchActivity.class);
                intent1.putExtra(SearchActivity.ADD_PLAY, true);
                intent1.putExtra(SearchActivity.ROOM_ID, mRoom);
                mContext.startActivity(intent1);
                break;
            case R.id.room_edit_play_list:
                Intent intent2 = new Intent(mContext, EditPlayListsActivity.class);
                intent2.putExtra(EditPlayListsActivity.ROOM_ID, mRoom);
                mContext.startActivity(intent2);
                break;

        }
    }

    public void setEditButtonVisible() {
        mEdit.setVisibility(View.VISIBLE);
    }
}
